package com.wangjw.tuling.netty.rpc.common;

import com.wangjw.tuling.netty.rpc.client.NettyClient;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by wangjianwen on 2018/12/11.
 */
public class ProxyFactory {

    public static <T> T getProxy(Class<T> interfaceClass, NettyClient proxyInvoker) {
        InvocationHandler handler = new JDKInvocationHandler(proxyInvoker, interfaceClass);
        ClassLoader classLoader = ProxyFactory.class.getClassLoader();
        T result = (T) Proxy.newProxyInstance(classLoader, new Class[] {interfaceClass}, handler);
        return result;
    }
}
